﻿
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;

namespace DataLibrary.Utility
{
    public class DateHelper
    {

        public static long ConvertDateTimeToInt(object timedayobj, object timeHourobj)
        {
            string timeday = timedayobj.ToString().Substring(0, 11);
            string timeHour = timeHourobj.ToString();

            var strs = timeHour.Split(':');
            int strHour = Convert.ToInt32(strs[0]);

            if (strHour >= 24)
            {
                DateTime day = Convert.ToDateTime(timeday); // 替换为给定的时间
                timeday = day.AddDays(1).ToString("yyyy-MM-dd");
                timeHour = (strHour % 24).ToString() + ":" + strs[1];
            }



            return ConvertDateTimeToInt(timeday + " " + timeHour);
        }

        public static long ConvertDateTimeToInt(string time)
        {
            DateTime givenTime = Convert.ToDateTime(time); // 替换为给定的时间
            //ToUniversalTime()将当前DateTime对象的值转换为世界标准时间(UTC)
            TimeSpan mTimeSpan = givenTime.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0);
            //得到精确到秒的时间戳（长度10位）
            long timestamp = (long)mTimeSpan.TotalSeconds;


            return timestamp;
        }


    }
}

